{include file='public/head' /}
<style type="text/css">
  .tablelist tr {
    border:1px solid #CFCFCF;
  }
  .tablelist tr td,.tablelist tr th{
    border:1px solid #CFCFCF;
  }
</style>
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main" style="padding:10px">
        <h1 class="page-header" style="color: #3399CC">管理员列表
        
          <button type="button" class="btn btn-info"  title="优化数据表" onclick="database('optimizes')"><span class="glyphicon glyphicon-trash"></span>优化表</button>
          <button type="button" class="btn btn-danger"  title="修复数据表" onclick="database('repairs')"><span class="glyphicon glyphicon-trash"></span>修复数据表</button>
         <!--  <a href="{:url('database/backup')}"><button type="button" class="btn btn-success"  title="备份数据表"><span class="glyphicon glyphicon-trash"></span>备份数据表</button></a> -->
        </h1>
        <div class="table-responsive" style="margin-top: -30px;border:none;">
          <form action="{:url('admin/admin/index')}" method="get" class="navbar-form navbar-right" role="search" style="margin-top: 20px;">
           <div class="input-group">
              <input type="text" class="form-control" autocomplete="off" placeholder="键入关键字搜索" value='{$Think.get.key}' name="key" style="width:190px">
            <span class="input-group">
             <input class="btn btn-primary" type="submit" value="搜索" style="border-radius: 0 3px 3px 0">&nbsp;
             <button class="btn btn-primary" name="all" value="1">显示全部</button>
              </span> </div>
           </form>
          <table class="table table-striped table-hover tablelist">
            <thead>
              <tr style="background-color: #3399CC;color: white">
                <th><input type="checkbox" id="all" style="position: relative;top:2px"/><span class="glyphicon glyphicon-th-large"></span> <span>选择</span></th>
                <th><span class="glyphicon glyphicon-user"></span> <span>数据库表</span></th>
                <th><span class="glyphicon glyphicon-map-marker"></span> <span>记录条数</span></th>
                <th><span class="glyphicon glyphicon-map-marker"></span> <span>占用空间</span></th>
                <th><span class="glyphicon glyphicon-tags"></span> <span>类型</span></th>
                <th><span class="glyphicon glyphicon-users"></span> <span>编码</span></th>
                <th><span class="glyphicon glyphicon-users"></span> <span>创建时间</span></th>
                <th><span class="glyphicon glyphicon-users"></span> <span>说明</span></th>
                <th><span class="glyphicon glyphicon-pencil"></span> <span>操作</span></th>
              </tr>
            </thead>
            <tbody>
               {volist name='db' id='vo'}
               <tr>
                 <td><input type="checkbox" value="{$vo.Name}"/></td>
                 <td>{$vo.Name}</td>
                 <td>{$vo.Rows}</td>
                 <td>{$vo.Data_length|format_bytes}</td>
                 <td>{$vo.Engine}</td>
                 <td>{$vo.Collation}</td>
                 <td>{$vo.Create_time}</td>
                 <td>{$vo.Comment}</td>
                 <td>
                  <a href="{:url('admin/database/optimize',['tables'=>$vo.Name])}" title="优化" rel="1" class="btn btn-danger btn-xs" name="see" style="font-size: 10px;"><span class="glyphicon glyphicon-zoom-in"></span> 优化</a>
                 <!--  <a href="{:url('database/optimize?tables='.$vo['Name'])}" title="优化" rel="1" class="btn btn-danger btn-xs" name="see" style="font-size: 10px;"><span class="glyphicon glyphicon-zoom-in"></span> 优化</a> -->
                  <a href="{:url('admin/database/repair',['tables'=>$vo.Name])}" title="修复" rel="1" class="btn btn-primary btn-xs" name="see" style="font-size: 10px;"><span class="glyphicon glyphicon-pencil"></span> 修复</a>
                </td>
               </tr>
               {/volist}
            </tbody>
          </table>
        </div>
       
    </div>
  </div>
</section>
<script>
  //单条记录删除
  $('.del').click(function(){
      var del = confirm("你确定要删除吗？");
       if(del == false){
        return false;
      }  
  });
  function database(url){
      var trObj = $(".tablelist tbody tr");
      var ids = new Array();
      var mainObjs = new Array();
      //遍历每一行
      for($i=0;$i<trObj.length;$i++){
         if(trObj.eq($i).find("input").attr('checked')){
            //组装ids数组
            ids[ids.length]=trObj.eq($i).find("input").val();
            //组装mainObj数组
            mainObjs[mainObjs.length]=trObj.eq($i);
         }
      }     
    if(ids.length>0){
        //启动ajax
        $.ajax({
            url:url,
            type:'post',
            data:{'tables':ids},
            async:false, 
            dataType:'json',
            success:function (d) {
                console.log(d);
                return false;
                if(d == 2){
                  alert('数据表优化完成');
                }else if(d == 3){
                  alert('数据表优化失败');
                }else if(d == 4){
                  alert('数据表修复完成');
                }else if(d == 5){
                  alert('数据表修复失败');
                }else{
                  alert('请求失败');
                }       
            }
        });
    }else{
       alert("你还没有进行选择");
    }  
  }
  //多选删除
  $('#deleteSelect').click(function(){
    //获取【被选择】的行的id
      var trObj = $(".tablelist tbody tr");
      var ids = new Array();
      var mainObjs = new Array();
      //遍历每一行
      for($i=0;$i<trObj.length;$i++){
         if(trObj.eq($i).find("input").attr('checked')){
            //组装ids数组
            ids[ids.length]=trObj.eq($i).find("input").val();
            //组装mainObj数组
            mainObjs[mainObjs.length]=trObj.eq($i);
         }
      }     
    if(ids.length>0){
        //启动ajax
        $.ajax({
            url:"{:url('optimizes')}",
            type:'post',
            data:{'tables':ids},
            async:false, 
            dataType:'json',
            success:function (d) {
                console.log(d);
                if(d == 2){
                  alert('数据表优化完成');
                }else if(d == 3){
                  alert('数据表优化失败');
                }else{
                  alert('请求失败');
                }
/*            if(d==1) {
                var a = confirm("你确定要删除吗？");
                if(a == true){
                   //将前端被选择的多选框所在的行移除DOM
                    for($i=0;$i<mainObjs.length;$i++){
                        mainObjs[$i].fadeOut(500,function(){
                            $(this).remove();
                            history.go(0);
                        });
                    }
                }else{
                   history.go(0);
                }
              } else if (d == 2) {
                     //删除失败
                   alert('删除失败');
               }*/

            }

        });
    }else{
       alert("你没有选择要删除的内容，请选择后再【批量删除】");
    }  
 
  });
  //全选或全不选
  $("#all").click(function(){ 
      if(this.checked){
         $(".tablelist tbody tr :checkbox").attr("checked", true);
        
      }else{
         $(".tablelist tbody tr :checkbox").removeAttr("checked", false);
      }
  });
</script>
</body>
</html>
